package com.ibeeking.gmc.global.g.rest.controller.v1;

import com.ibeeking.gmc.global.g.rest.service.IDictTypeService;
import com.ibeeking.found.common.annotation.LoginUser;
import com.ibeeking.found.common.entity.CurrentUser;
import com.ibeeking.gmc.global.service.common.param.DictTypeParam;
import com.ibeeking.gmc.global.service.common.query.DictTypePageQuery;
import com.ibeeking.gmc.global.service.common.vo.DictTypePageVO;
import com.ibeeking.gmc.global.service.common.vo.DictTypeVO;
import com.ibeeking.nematos.constants.enums.OperateLogTypeEnum;
import com.ibeeking.nematos.log.annotation.Log;
import com.ibeeking.nematos.utils.base.BaseValidationGroup;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @ClassName DictTypeController控制器
 * @Description
 * @Author ibeeking
 * @Date 2020-12-02 16:06
 **/
@RestController
@RequestMapping("/g/dictType/v1")
public class DictTypeController {

    @Resource
    private IDictTypeService dictTypeServiceImpl;

    @Log(logType = OperateLogTypeEnum.QUERY, describe = "分页查询字典类型列表")
    @PostMapping(value = "/pageList")
    public Page<DictTypePageVO> pageList(@RequestBody DictTypePageQuery dictTypePageQuery) {
        return dictTypeServiceImpl.pageList(dictTypePageQuery);
    }

    @Log(logType = OperateLogTypeEnum.SAVE, describe = "新增字典类型")
    @PostMapping(value = "/add")
    public Boolean add(@LoginUser CurrentUser currentUser, @RequestBody @Validated(BaseValidationGroup.Insert.class) DictTypeParam dictTypeParam) {
        dictTypeParam.setCreateBy(currentUser.getId());
        return dictTypeServiceImpl.add(dictTypeParam);
    }

    @Log(logType = OperateLogTypeEnum.MODIFY, describe = "修改字典类型")
    @PostMapping(value = "/modify")
    public Boolean modify(@LoginUser CurrentUser currentUser, @RequestBody @Validated(BaseValidationGroup.Update.class) DictTypeParam dictTypeParam) {
        dictTypeParam.setModifyBy(currentUser.getId());
        return dictTypeServiceImpl.modify(dictTypeParam);
    }

    @Log(logType = OperateLogTypeEnum.QUERY, describe = "查询字典类型")
    @GetMapping(value = "/view/{id}")
    public DictTypeVO view(@PathVariable("id") Long id) {
        return dictTypeServiceImpl.view(id);
    }

    @Log(logType = OperateLogTypeEnum.MODIFY, describe = "启用/禁用字典类型")
    @GetMapping(value = "/changeStatus/{id}/{status}")
    public Boolean changeStatus(@LoginUser CurrentUser currentUser, @PathVariable("id") Long id, @PathVariable("status") Integer status) {
        return dictTypeServiceImpl.changeStatus(id, status, currentUser.getId());
    }

    @Log(logType = OperateLogTypeEnum.DEL, describe = "删除字典类型")
    @GetMapping(value = "/del/{id}")
    public Boolean del(@PathVariable("id") Long id) {
        return dictTypeServiceImpl.del(id);
    }
}